import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/routes/tab_moments/xindong_user_moments_yemian.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_ctr.dart';
import 'package:xindong/routes/userspace/view/xindong_kongjian_title_container.dart';
import 'package:xindong/widgets/common/xindong_round_image.dart';

class XinDongKongJianInfoMoment extends StatelessWidget {
  const XinDongKongJianInfoMoment({super.key});

  @override
  Widget build(BuildContext context) {
    const double spacing = 8.0;
    final itemWidth = (screenWidth - 2 * 15 - 4 * spacing) / 5;
    return GetBuilder<XinDongKongJianCtr>(
      id: XinDongKongJianCtr.updateIdLoadingMoment,
      builder: (controller) {
        final dataList = [];
        for (var element in controller.moments) {
          dataList.addAll(element.sumbImage);
        }
        if (dataList.isEmpty) {
          return const SizedBox();
        }
        return XinDongKongJianTitleContainer(
          title: '最新动态',
          onTap: () {
            XinDongPageSingleton.instance.pushYeMian(XinDongUserMomentsYeMian(
              userId: controller.userspace!.uid,
              name: controller.userspace!.getName,
            ));
          },
          children: [
            SizedBox(
              height: itemWidth,
              child: ListView.separated(
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
                itemCount: dataList.length,
                itemBuilder: (BuildContext context, int index) {
                  return XinDongRoundImage(
                    url: dataList[index],
                    size: itemWidth,
                  );
                },
                separatorBuilder: (BuildContext context, int index) {
                  return const SizedBox(width: spacing);
                },
              ),
            ),
          ],
        );
      },
    );
  }
}
